from yaml import safe_load
from .setting import DbConfig,BlockChainConfig

def convert_to_object():
    with open('D:/pyWorkSpace/readOnChainData/config/config.yml', 'r',encoding='utf-8') as f:
        data = safe_load(f)
    db_data = data.get('Database',{})
    db_config = DbConfig(
        DbType=db_data.get('DbType'),
        DbName=db_data.get('DbName'),
        Host=db_data.get('Host'),
        Port=db_data.get('Port'),
        Username=db_data.get('Username'),
        Pwd=db_data.get('Pwd'),
        Charset=db_data.get('Charset'),
        ParseTime=db_data.get('ParseTime')
    )

    block_chain_data = data.get('BlockChain',{})
    block_chain_config = BlockChainConfig(
        RpcUrl=block_chain_data.get('RpcUrl')
    )

    return db_config,block_chain_config


if __name__ == '__main__':
    convert_to_object()